import { Module } from 'vuex'
import { getGetDict } from '@/api/common'
import { it } from 'element-plus/es/locale';

// 存放地
export interface DepositPlaceState {
  data: {
    key: string;
    name: string;
  }[]
}

// eslint-disable-next-line
const depositPlace: Module<DepositPlaceState, any> = {
  namespaced: true,
  state: () => ({
    data: []
  }),
  getters: {
    getName(state) {
      return (key: string) => state.data.find(item => item.key === key)?.name
    }
  },
  mutations: {
    SET_DEPOSIT_PLACE (state, payload) {
      state.data = payload
    }
  },
  actions: {
    getDict ({ commit }) {
      return new Promise((resolve, reject) => {
        getGetDict('lose_deposit_place').then(res => {
          if (res && res.data) {
            const list = []
            for (let item of res.data.list) {
              if (item.name === '捡拾人手中') {
                break
              }
              list.push(item)
            }
            commit('SET_DEPOSIT_PLACE', list)
            resolve(res)
          } else {
            reject(res)
          }
        }).catch(reject)
      })
    }
  }
}

export default depositPlace
